//
//  WDLeftMenuCell.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/1.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDLeftMenuCell.h"
#import "WDLeftMenu.h"

@interface WDLeftMenuCell ()
/** 图标 */
@property(nonatomic, weak) UIImageView *iconView;
/** 菜单项 */
@property(nonatomic, weak) UILabel *menuLabel;

@end

@implementation WDLeftMenuCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        //取消选中样式
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        //图标
        UIImageView *iconView = [[UIImageView alloc] init];
        [self.contentView addSubview:iconView];
        iconView.contentMode = UIViewContentModeScaleAspectFit;
        self.iconView = iconView;
        self.backgroundColor = [UIColor clearColor];
        
        [iconView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(16);
            make.width.height.equalTo(20);
            make.centerY.equalTo(self.contentView.centerY);
        }];
        
        
        //栏目名
        UILabel *meunLabel = [[UILabel alloc] init];
        meunLabel.textColor = ColorForRGB(0xffffff);
        meunLabel.font = [UIFont systemFontOfSize:17];
        [self.contentView addSubview:meunLabel];
        self.menuLabel = meunLabel;
        
        [meunLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconView.right).offset(16);
            make.centerY.equalTo(self.contentView.centerY);
        }];
    }
    return self;
}

+ (instancetype)leftMenuCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"LeftMenu";
    
    WDLeftMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        
        cell = [[WDLeftMenuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    
    return cell;
}

//设置数据
- (void)setLeftMenu:(WDLeftMenu *)leftMenu
{
    _leftMenu = leftMenu;
    self.iconView.image = [UIImage imageNamed:_leftMenu.icon];
    self.menuLabel.text = _leftMenu.menu;
    
}

@end
